<?php
//---- set error warning ----/
//error_reporting(E_ALL);
ini_set("display_errors", 0); // 0: no display - 1: display  note, warning,...
//---- end ----/
@session_start();
global $db, $function, $smarty;

include("include/include.php");

$smarty->assign("title", title);

$mod = isset($_GET['mod']) ? ($_GET['mod']) : "";
switch(strtolower($mod)) {

	default:
	case "login":
		if(isset($_POST['btn_login'])) {
			$uname = stripslashes($function->FixQuotes($_POST['username']));
			$upass = stripslashes($function->FixQuotes($_POST['password']));
			$oUser = new User();
			$_SESSION['user_logged'] = $oUser->userLogin($uname, $upass);
			if($_SESSION['user_logged'] != "") {
				if($_SESSION['user_logged']['UserType'] == "a") { // a = admin
					return $function->goto_url("?mod=hadmin");
				}
				if($_SESSION['user_logged']['UserType'] == "t") { // t = tutor
					return $function->goto_url("?mod=htutor");
				}
				if($_SESSION['user_logged']['UserType'] == "s") { // s = student
					return $function->goto_url("?mod=hstudent");
				}
				if($_SESSION['user_logged']['UserType'] == "ca") { // ca = content admin
					return $function->goto_url("?mod=hcadmin");
				}
			} else {
				return $function->goto_url("?mod=login");
			}
		} else {
			return $smarty->display("signin.html");
		}
	break;
	
	case "logout":
		session_destroy();
		return $function->goto_url("?mod=login");	
	break;

	case "hstudent":
		if($_SESSION['user_logged']['UserType'] == "s") { // s = student
			$smarty->assign("panel_mod", home_student());
			return $smarty->display("homepage.html"); // if using homepage.html for all users (btw, we can change homepage.html for each user)
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	case "hadmin":
		if($_SESSION['user_logged']['UserType'] == "a") { // a = admin
			$smarty->assign("panel_mod", "Admin");
			return $smarty->display("homepage.html");
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	case "hcadmin":
		if($_SESSION['user_logged']['UserType'] == "ca") { // ca = content admin
			$smarty->assign("panel_mod", home_ca());
			return $smarty->display("homepage.html");
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	case "htutor":
		if($_SESSION['user_logged']['UserType'] == "t") { // t = tutor
			$smarty->assign("panel_mod", home_tutor());
			return $smarty->display("homepage.html");
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	case "camu":
		if($_SESSION['user_logged']['UserType'] == "ca") { // ca = content admin
			$smarty->assign("panel_mod", process_ca_modules_units());
			return $smarty->display("homepage.html");
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	/*-----------------------------------------
		Question Bank module for Content Admin
	------------------------------------------*/
	case "questionbank":
		if($_SESSION['user_logged']['UserType'] == "ca") { // ca = content admin
			$smarty->assign("panel_mod", process_ca_questionbank());
			return $smarty->display("homepage.html");
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	case "markattempt":
		if($_SESSION['user_logged']['UserType'] == "t") { // t = tutor
			$smarty->assign("panel_mod", process_tutor());
			return $smarty->display("homepage.html");
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	case "student":
		if($_SESSION['user_logged']['UserType'] == "s") { // s = student
			$smarty->assign("panel_mod", process_student());
			return $smarty->display("homepage.html");
		} else {
			echo "You don't have permission to view this page.";exit;
		}
	break;
	
	
}	
?>